home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 April / Software of the Month Club 1996 April.iso / pc / os2 / psutils / src / maketext < prev    next >
Text File  |  1996-02-21  |  1KB  |  38 lines

  1. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
  2.    & eval 'exec perl -S $0 $argv:q'
  3.    if 0;
  4.  
  5. # maketext: perl filter to substitute names in scripts and man pages.
  6.  
  7. %change = ();            # names -> substitutions
  8.  
  9. # get release and patchlevel for all scripts
  10. open(H, "patchlev.h") || die "can't open patchlev.h";
  11. while(<H>) {
  12.    $change{$1} = $2 if /^\#define\s*(\S*)\s*(\S*)/;
  13. }
  14. close(H);
  15.  
  16. foreach (@ARGV) {
  17.    if (/MAN=(.*)/) {        # name.ext name.ext -> name(ext), name(ext)
  18.       local(@man) = split(' ', $1);
  19.       $change{"MAN"} = join(", ", grep(s/\.(.)/($1)/, @man));
  20.    } elsif (/PERL=(\/.*)/) {    # substitute name for value
  21.       $change{"PERL"} = "\#!$1\neval 'exec perl -S \$0 \"\$\@\"'\n\tif \$running_under_some_shell;\n";
  22.       $change{"END"} = "";
  23.    } elsif (/PERL=(.*)/) {    # substitute name for value
  24.       $change{"PERL"} = "\@rem = '-*- Perl -*-\n\@echo off\n$1 -S %0.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9\ngoto endofperl\n';\n";
  25.       $change{"END"} = "__END__\n:endofperl\n";
  26.    } elsif (/(.*)=(.*)/) {    # substitute name for value
  27.       $change{$1} = $2;
  28.    } else {            # open file and substitute
  29.       local(@change) = keys %change;
  30.       open(FILE, $_) || die "can't open $_";
  31.       while ($line = <FILE>) {
  32.      grep($line =~ s/\@$_\@/$change{$_}/g, @change);
  33.      print $line;
  34.       }
  35.       close(FILE);
  36.    }
  37. }
  38.